<?php
/**
 * 积分规则
 * edition ：v1
 * create time：2021-06-08
 * author: acker
 */
namespace App\Admin\Controllers\System;



use App\Http\Controllers\Controller;
use App\Models\yb\SettingModel;
use Encore\Admin\Form;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Grid;
use Encore\Admin\Show;


class IntegralController extends Controller
{
    use ModelForm;

    protected $header = '积分规则';


    /**
     * 新增
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header($this->header);
            $content->description('创建');
            $content->body($this->form());

        });
    }

    /**
     * 编辑
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header($this->header);
            $content->description('编辑');
            $content->body($this->form()->edit($id));

        });
    }


    /**
     * @return mixed
     */
    public function form(){

        $form = new Form(new SettingModel());

        $form->currency('invitation_reward','邀请奖励')->symbol('积分');

        $form->currency('registration_reward','注册奖励')->symbol('积分');

            $form->currency('consumption_inverse_price','消费')->symbol('元');
            $form->currency('consumption_inverse_points','可获得')->symbol('积分');

        $form->editor('withdrawal_rule','积分规则');

        $form->tools(function (Form\Tools $tools) {
            $tools->disableView();
            $tools->disableDelete();
            $tools->disableList();
        });

        $form->footer(function ($footer) {
            // 去掉`查看`checkbox
            $footer->disableViewCheck();
        });

        $form->saved(function (Form $form) {
            return redirect('/admin/system/Integral/rule/1/edit');
        });

        return $form;
    }


}
